package edu.sctu.zhengsenwen.month201506.day20150616.network;

import java.io.*;
import java.net.HttpURLConnection;
import java.net.URL;

/**
 * Created by user15 on 2015/6/17.
 */
public class URLConectionRead {

   public static void getConnection(String path) throws IOException {

       URL url = new URL(path);

       int count =0;
       byte[] buffer = new byte[1024];

       HttpURLConnection httpURLConnection = (HttpURLConnection) url.openConnection();

       httpURLConnection.setRequestMethod("POST");

       httpURLConnection.setDoInput(true);
       httpURLConnection.setDoOutput(true);
       httpURLConnection.setUseCaches(false);

       System.out.println("999999999");
       OutputStream outputStream = httpURLConnection.getOutputStream();
       outputStream.write(buffer);
       outputStream.close();
       System.out.println("7777777");

       InputStream inputStream = httpURLConnection.getInputStream();


       File file = new File("D://ok.txt");
       FileInputStream fileInputStream = new FileInputStream(file);



       while((fileInputStream.read()) != -1){

           outputStream.write(buffer);
           System.out.println(new String(buffer,0,count,"utf-8"));
       }

   }

    public static void main(String[] args) throws IOException {

        getConnection("http://www.baidu.com");

    }


}
